package cn.dnuihyy406.dnuifood_16110100406.controller.mefragment;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.dnuihyy406.dnuifood_16110100406.R;
import cn.dnuihyy406.dnuifood_16110100406.bean.ResultBean;
import cn.dnuihyy406.dnuifood_16110100406.listener.OnRetrofitListener;
import cn.dnuihyy406.dnuifood_16110100406.model.UserImformationModel;

public class CommentActivity extends AppCompatActivity implements OnRetrofitListener<Object> {
    private EditText t_Comment;
    private Button  Comment;
    String item_id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment);
        initViews();
        initData();
        initEvents();
    }

    @Override
    public void onSuccess(Object object, int flag) {
        if(((ResultBean)object).getSuccess().equals("1")){
            Toast.makeText(CommentActivity.this,"添加成功",Toast.LENGTH_SHORT).show();
            finish();
        }
        else
        {
            Toast.makeText(CommentActivity.this,"添加错误",Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onFailure(String msg) {
        Toast.makeText(CommentActivity.this,msg,Toast.LENGTH_SHORT).show();
    }

    void initViews(){
        Comment=findViewById(R.id.o_comment1);
        t_Comment=findViewById(R.id.o_comment);
    }

    void initData(){
        item_id=getIntent().getStringExtra("itemid");
    }

    void initEvents(){
        Comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                commentit();
            }
        });
    }

    private void commentit(){
        UserImformationModel userImformationModel=new UserImformationModel();
        userImformationModel.updateComment(item_id,t_Comment.getText().toString(),this);
    }

}
